<?php
add_action('admin_init','init_theme_options');

function init_theme_options(){
	if(false===get_option('sb_theme_display_options')){add_option('sb_theme_display_options');}
	add_settings_section('general_section', 'General Options', 'create_gen_options', 'sb_theme_display_options');
	add_settings_field('show_header','Header','toggle_header','sb_theme_display_options','general_section',array('Toggle the header'));
	add_settings_field('show_content','Content','toggle_content','sb_theme_display_options','general_section',array('Toggle the content'));
	add_settings_field('show_footer','Footer','toggle_footer','sb_theme_display_options','general_section',array('Toggle the footer'));
	register_setting('sb_theme_display_options', 'sb_theme_display_options');
	
}
function create_gen_options(){
	 echo '<p>Select which areas of content you wish to display.</p>';  
}

function toggle_fb($args){
	$options = get_option('sb_theme_social_options');
	$html = '<input type = "checkbox" name = "sb_theme_social_options[show_facebook]" id ="show_facebook" value ="1"'
			. checked(1, $options['show_facebook'], false)
			.'/>'
			. '<label for ="show_fb">'.$args[0].'</label>';
	echo $html;
}
function toggle_header($args){
	$options = get_option('sb_theme_display_options');
	$html = '<input type = "checkbox" name = "sb_theme_display_options[show_header]" id ="show_header" value ="1"'
			. checked(1, $options['show_header'], false)
			.'/>'
			. '<label for ="show_header">'.$args[0].'</label>';
	echo $html;
}
function toggle_content($args){
	$options = get_option('sb_theme_display_options');
	$html = '<input type = "checkbox" name = "sb_theme_display_options[show_content]" id ="show_content" value ="1"'
			. checked(1, $options['show_content'], false)
			.'/>'
			. '<label for ="show_content">'.$args[0].'</label>';
	echo $html;
}
function toggle_footer($args){
	$options = get_option('sb_theme_display_options');
	$html = '<input type = "checkbox" name = "sb_theme_display_options[show_footer]" id ="show_footer" value ="1"'
			. checked(1, $options['show_footer'], false)
			.'/>'
			. '<label for ="show_footer">'.$args[0].'</label>';
	echo $html;
}

function sandbox_theme_menu(){
	add_theme_page('Sandbox Theme Options', 'Sandbox Options', 'administrator', 's-t-o', 'theme_display');
}
add_action('admin_menu','sandbox_theme_menu');
function theme_display(){ ?>
	<div class="wrap">
		<div id ="icon-themes" class="icon32"></div>
		<h2>Sandbox Theme Options</h2>
		<?php		 settings_errors(); ?>
		<form method="post" action ="options.php">
			<?php			 settings_fields('sb_theme_display_options'); ?>
			<?php			 do_settings_sections('sb_theme_display_options'); ?>
			<?php			 submit_button(); ?>
		</form>
		<form method="post" action ="options.php">
			<?php			 settings_fields('sb_theme_social_options'); ?>
			<?php			 do_settings_sections('sb_theme_social_options'); ?>
			<?php			 submit_button(); ?>
		</form>
	</div>
<?php }